package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import common.ServerResponse;
import service.IManageOrderService;
import service.impl.ManageOrderServiceImpl;
import util.myUtil;

@WebServlet("/manage/order")
public class ManageOrderServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
   
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		myUtil.setHead(request, response);
		String type=request.getParameter("type");
		System.out.println("进入订单管理servlet，此时的type是："+type);
		if("list".equals(type)) {
			list(request, response);
		}
		else if("search".equals(type)) {
			search(request, response);
		}
		else if("detail".equals(type)) {
			detail(request, response);
		}
		else if("send_goods".equals(type)) {
			send_goods(request,response);
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}
	
	/*操作区****************************/
	/**********************************/
	
	//订单list
	protected void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		ServerResponse se=null;
//		HttpSession session =request.getSession();
//        Object user_id=session.getAttribute("id");
		String user_id="1";
        if(user_id==null) {
        	se=ServerResponse.serverResponseByError("管理员未登录");
        }else {
        	String pageNum=request.getParameter("pageNum");
    		String pageSize=request.getParameter("pageSize");
    		System.out.println("此时的page分页两参数是："+pageNum+" "+pageSize);
    		IManageOrderService o=new ManageOrderServiceImpl();
    		se=o.list(pageNum, pageSize);
        }
		
		myUtil.getjson(se, response);
	}
	
	//订单search
	protected void search(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String order_no=request.getParameter("order_no");
		System.out.println("此时订单编号为："+order_no);
		IManageOrderService o=new ManageOrderServiceImpl();
		myUtil.getjson(o.search(order_no), response);
	}
	
	//订单detail
	protected void detail(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String order_no=request.getParameter("order_no");
		System.out.println("此时订单编号为："+order_no);
		IManageOrderService o=new ManageOrderServiceImpl();
		myUtil.getjson(o.detail(order_no), response);
	}
	
	//订单发货
	protected void send_goods(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String order_no=request.getParameter("order_no");
		System.out.println("此时订单编号为："+order_no);
		IManageOrderService o=new ManageOrderServiceImpl();
		myUtil.getjson(o.send_goods(order_no), response);
	}
	
	
	

}
